//
// Created by Administrator on 2021/11/10.
// May Saint Diana bless you!
//
#include <iostream>
#include <vector>
#include <queue>
#include <tuple>

using namespace std;

class Solution {
public:
    enum rc {
        ROW, COL
    };

    vector<vector<int>> restoreMatrix(vector<int> &rowSum, vector<int> &colSum) {
        unsigned int m = rowSum.size(), n = colSum.size();
        vector<vector<int>> ans(m, vector<int>(n, 0));
        for (int i = 0; i < m; ++i) {
            for (int j = 0; j < n; ++j) {
                int less = min(rowSum[i], colSum[j]); // 每个格子都尽量填最大的值，最大可以是它的行列和的最小值
                ans[i][j] = less;
                rowSum[i] -= less;
                colSum[j] -= less;
                if (rowSum[i] == 0)  // 如果这一行已经呗用完，就到下一行去
                    break;
            }
        }
        return ans;
    }
};

int main() {
    vector<int> rowSum{5, 7, 10};
    vector<int> colSum{8, 6, 8};
    Solution solution;
    auto ans = solution.restoreMatrix(rowSum, colSum);
    for (const auto &row:ans) {
        for (const auto &x:row) {
            cout << x << " ";
        }
        cout << endl;
    }
    return 0;
}


